import { constantRoutes, asyncRoutes } from '@/router'
export default {
  namespaced: true,
  state: {
    return: {
      routes: [...constantRoutes]
    }
  },
  mutations: {
    setRoutes(state, data) {
      state.routes = [...constantRoutes, ...data]
    }
  },
  actions: {
    filtersRouters(ctx, menus) {
      const userAsyncRoutes = []
      asyncRoutes.forEach(item => {
        if (menus.includes(item.name)) userAsyncRoutes.push(item)
      })
      userAsyncRoutes.push({ path: '*', redirect: '/404', hidden: true })
      ctx.commit('setRoutes', userAsyncRoutes)
      return userAsyncRoutes
    }
  }
}
